# -*- coding:utf-8 -*-
#! python3

# FaceCat-Python
#Shanghai JuanJuanMao Information Technology Co., Ltd 

from facecat_objc import *

gPaint = FCPaint() #创建绘图对象

#加载示例
def loadUI():
	xml = """<?xml version="1.0" encoding="utf-8"?>
	<html xmlns="facecat">
	<head>
	</head>
	<body>
		<div dock="fill" type="tab" selectedindex="0">
		<div name="TabPage" text="可视化生成" type="tabpage">
			<div type="layout" name="LayoutDiv" text="LayoutDiv" location="30,30" size="265,99" showhscrollbar="True">
			<input type="button" name="Button" text="Button" location="27,26" size="100,20" />
			<input type="button" name="Button2" text="Button2" location="27,26" size="100,20" />
			<input type="button" name="Button3" text="Button3" location="27,26" size="100,20" />
			<input type="button" name="Button4" text="Button4" location="27,26" size="100,20" />
			<input type="button" name="Button5" text="Button5" location="27,26" size="100,20" />
			<input type="button" name="Button6" text="Button6" location="27,26" size="100,20" />
			</div>
			<div type="layout" name="LayoutDiv2" text="LayoutDiv2" location="71,210" size="135,234" layoutstyle="TopToBottom" showvscrollbar="True">
			<input type="button" name="Button7" text="Button7" location="27,26" size="100,100" />
			<input type="button" name="Button8" text="Button8" location="27,26" size="100,100" />
			<input type="button" name="Button9" text="Button9" location="27,26" size="100,100" />
			<input type="button" name="Button10" text="Button10" location="27,26" size="100,100" />
			<input type="button" name="Button11" text="Button11" location="27,26" size="100,100" />
			<input type="button" name="Button12" text="Button12" location="27,26" size="100,100" />
			</div>
		</div>
		<div name="TabPage2" text="代码创建" type="tabpage" />
		</div>
	</body>
	</html>
	"""
	renderFaceCat(gPaint, xml)
	tabPage = findViewByName("TabPage2", gPaint.views)
	layoutDiv = FCLayoutDiv()
	layoutDiv.location = FCPoint(50, 50)
	layoutDiv.size = FCSize(250, 100)
	layoutDiv.showHScrollBar = True
	addViewToParent(layoutDiv, tabPage)
	for i in range(0,10):
		button = FCButton()
		location = FCPoint(0, 0)
		button.size = FCSize(100, 40)
		addViewToParent(button, layoutDiv)
		button.text = "Button"
	resetLayoutDiv(layoutDiv);

class AppDelegate(NSObject):
	def windowWillClose_(self, notification):
		os._exit(0)
	def applicationDidFinishLaunching_(self, notification):
		gPaint.size = FCSize(900, 770)
		window = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(
		NSMakeRect(0, 0, gPaint.size.cx, gPaint.size.cy),
		15,
		NSBackingStoreBuffered,
		False
		)
		window.setDelegate_(self)
		window.orderFrontRegardless()
		view = FCUIView.alloc().initWithFrame_(NSMakeRect(0, 0, gPaint.size.cx, gPaint.size.cy))
		view.paint = gPaint
		window.setContentView_(view)
		gPaint.view = view
		loadUI()

app = NSApplication.sharedApplication()
delegate = AppDelegate.alloc().init()
app.setDelegate_(delegate)
app.run()
